package com.liwei.lwmail.order.web;

import com.liwei.lwmail.order.service.OrderService;
import com.liwei.lwmail.order.vo.OrderConfirmVo;
import com.liwei.lwmail.order.vo.OrderSubmitRespVo;
import com.liwei.lwmail.order.vo.OrderSubmitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.concurrent.ExecutionException;

@Controller
public class OrderWebController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/toTrade")
    public String toTrade(Model model) throws ExecutionException, InterruptedException {
        //展示订单信息
        OrderConfirmVo confirmVo = orderService.confirmOrder();
        model.addAttribute("orderConfirmData",confirmVo);
        return "confirm";
    }

    /**
     * 提交订单
     * @param vo
     * @return
     */
    @PostMapping("/subOrder")
    public String subOrder(OrderSubmitVo vo, Model model){
        OrderSubmitRespVo respVo = orderService.subOrder(vo);
        if (respVo.getCode() == 0){
            model.addAttribute("respVo",respVo);
            return "pay";
        }else {
            System.out.println(respVo.getCode());
            return "redirect:http://order.lwmall.com/toTrade";
        }

    }
}
